//
//  TCLYCommunityModel.m
//  YuErmuYing
//
//  Created by LYang on 16/8/12.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYCommunityModel.h"
#import "HttpRequest.h"
#import "AFNetworking.h"
@implementation TCLYCommunityModel

-(void) loadOrderParameter:(NSDictionary *)parameter{
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    //代付款
    NSString * urlStr1 = @"http://112.74.114.1/Parenting/index.php/api/order/order_not_pay";
    [httpRequest postWithURLString:urlStr1 parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.payArr = json[@"data"];
//        NSLog(@"pay%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadOrderSucceed" object:self];
    } failure:^(NSError *error) {
//        NSLog(@"%@",error);
    }];
    //待发货
    NSString * urlStr2 = @"http://112.74.114.1/Parenting/index.php/api/order/order_send";
    [httpRequest postWithURLString:urlStr2 parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.deliveryArr = json[@"data"];
//        NSLog(@"delicery%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadOrderSucceed" object:self];
    } failure:^(NSError *error) {
//        NSLog(@"%@",error);
    }];
    //待收货
    NSString * urlStr3 = @"http://112.74.114.1/Parenting/index.php/api/order/order_receive";
    [httpRequest postWithURLString:urlStr3 parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.goodsArr = json[@"data"];
        NSLog(@"%@",json);
    } failure:^(NSError *error) {
        NSLog(@"goods%@",error);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadOrderSucceed" object:self];
    }];
    //待评价
    NSString * urlStr4 = @"http://112.74.114.1/Parenting/index.php/api/order/order_rated";
    [httpRequest postWithURLString:urlStr4 parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.evaluationArr = json[@"data"];
        NSLog(@"evaluation%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadOrderSucceed" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    //待晒单
    NSString * urlStr5 = @"http://112.74.114.1/Parenting/index.php/api/order/prizer";
    [httpRequest postWithURLString:urlStr5 parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.publishedArr = json[@"data"];
        NSLog(@"evaluation%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadOrderSucceed" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//取消订单的接口
-(void)cancelParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/Parenting/index.php/api/order/order_order";
    
    NSLog(@"%@",parameter);
    
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",json);
        if ([json[@"data"] isEqual:@1]) {
            self.deliveryArr = nil;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"cancelOrderSucced" object:self];
        }else{
            if ([json[@"msg"] isEqual:@400]) {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"cancelOrderError" object:self];
                return ;
            }
            self.deliveryArr = json[@"data"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"cancelOrderSucced" object:self];
        }
        
    } failure:^(NSError *error) {
        
    }];
}
//提醒订单的接口
-(void)deliveryParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/Parenting/index.php/api/order/order_remind";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
//        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
    } failure:^(NSError *error) {
        
    }];
}
//确认收货的接口
-(void)goodsParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/Parenting/index.php/api/order/order_confirm";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",json);
        if ([json[@"data"] isEqual:@1]) {
            self.goodsArr = nil;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"goodsOrder" object:self];
        }else{
            self.goodsArr = json[@"data"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"goodsOrder" object:self];
        }
    } failure:^(NSError *error) {
        
    }];
}
//评价的接口哦
-(void) evaluationSucceedParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/Parenting/index.php/api/order/addcomment";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
//        self.evaluationSucceedArr = json[@"data"];
        NSLog(@"%@",json);
    } failure:^(NSError *error) {
        
    }];
}

//晒单的接口哦
-(void) publishedSucceedParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/Parenting/index.php/api/order/shine";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"阿萨斯%@",json);
        NSLog(@"adasd%@",[NSString stringWithFormat:@"%@",json[@"data"]]);
    } failure:^(NSError *error) {
        
    }];
}

//上传图片的接口
-(void) uploadImageArray:(NSArray *) imageArray Parameter:(NSDictionary *)parameter ParamName:(NSString *)paramName FileName:(NSString *)fileName MimeType:(NSString *)mimetype UrlStr:(NSString *)urlStr{
    NSLog(@"111111");
    NSURLSessionConfiguration * conf = [NSURLSessionConfiguration defaultSessionConfiguration];
    AFHTTPSessionManager * manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:conf];
    for (UIImage * image in imageArray) {
        NSData * imageData = UIImageJPEGRepresentation(image, 1);
    //申明请求的数据是json类型
    manager.requestSerializer=[AFJSONRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager POST:urlStr parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        // 上传图片，以文件流的格式
        [formData appendPartWithFileData:imageData name:paramName fileName:fileName mimeType:mimetype];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (self.isInformation == YES) {
            NSLog(@"是YES%@",responseObject);
            self.updateInformationStr = responseObject[@"msg"];
            NSLog(@"%@",self.updateInformationStr);
            [[NSNotificationCenter defaultCenter] postNotificationName:@"updateInformationSucceed" object:self];
        }else{
            NSLog(@"是NO");
            NSLog(@"%@",responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
    }
}

@end
